<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>文章添加--layui后台管理模板</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport"
	content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="format-detection" content="telephone=no">
<link rel="stylesheet" href="../../js/layui/css/layui.css"
	media="all" />
<script src="../../js/layui/layui.js"></script>
<link rel="stylesheet" href="../../css/font_eolqem241z66flxr.css"
	media="all" />
<link rel="stylesheet" href="../../css/news.css" media="all" />
<style type="text/css">
.layui-table-cell {
	text-align: center;
	height: auto;
	white-space: normal;
	width: auto;
}
</style>
</head>
<body class="childrenBody">
	<script type="text/html" id="barDemo">	
		<a class="layui-btn layui-btn-sm" lay-event="save" ><i class="layui-icon layui-icon-save"></i>保存</a>
	</script>
	<table class="layui-table" id="news" lay-filter="table">
	</table>


	<script type="text/javascript">
	layui.use([ 'upload', 'layer' ,'table'], function() {
		var upload = layui.upload, $ = layui.$,table=layui.table, layer = layui.layer;
		
		 var data=JSON.parse(sessionStorage.getItem("product"));
			
			table.render({
				elem : '#news',
				url : 'http://localhost:8080/Greenleaf/pdtSize/getstock',//数据接口
				where : {
					alternative1 : data.pdtId
				},
				page : true, 
				 groups: 1,
				 limit:3,
				 limits:[5,6,7], 
				cols : [ [ //表头
				{field : 'sizeId',title : '编号',sort : true}
				,{field : 'sizeName',title : '规格'}
				,{field : 'stock',title : '库存(点击编辑)',edit:'text'}
				,{title : '保存',align : 'center',fixed : 'right',toolbar : '#barDemo'}
				] ],
				id : "ProductReload"
			});
			table.on('tool(table)',function(obj) {
				var data = obj.data; 
				var layEvent = obj.event; 
				var tr = obj.tr; 
				sessionStorage.setItem("product",
						JSON.stringify(data));
				if (layEvent === 'save') { //删除
					layer.confirm('确定保存',function(index) {
							layer.close(index);
								$.post("http://localhost:8080/Greenleaf/pdtSize/update",
										{
											sizeId: data.sizeId
											,stock : data.stock
										},
											function(res) {
												if (res.success) {obj.del();
													layer.msg('删除成功',{
															icon : 1,
														time : 1500
																});
											} else {
												layer.msg(res.message,{
													icon : 2,
													time : 1500
											});
									}
							location.reload();
						},"json")
			});
				} 
			});
	});
	
	</script>

</body>
</html>